package com.zzyl.mapper;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.entity.Reservation;
import com.zzyl.vo.TimeCountVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ReservationMapper extends BaseMapper<Reservation> {


    //查询取消预约次数
    @Select("select count(1)  from app_reservation where update_by=#{userId} and status=2 and update_time between #{begin} and #{end}")
    Integer getCancelledCount(Long userId, DateTime begin,DateTime end);

    //查询每个时间段剩余预约次数
    //timecountvo中的计数是count 所以此处要将6-count命名为count
    @Select("select time,6-count(1) count from app_reservation where time between #{begin} and #{end} and status!=2 group by time ")
    List<TimeCountVo> getTimeCount(LocalDateTime begin,LocalDateTime end);

}
